package gui;

import image.ImageManager;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import body.Marine;

/**
 * 游戏窗体
 * 
 */
@SuppressWarnings("serial")
public class GameFrame extends BufferFrame implements Runnable{
	

//	public Mouse mouse = new Mouse();
//	public static Marine m = new Marine(100, 100);
	
	public static MouseCentor mouse = new MouseCentor();
	
	public static MouseOval oval = new MouseOval();
	
	/**
	 * 鼠标按键
	 */
	public int button; 
	
	public GameFrame() {
		super(800, 600);
//		Toolkit.getDefaultToolkit().createCustomCursor(ImageManager.mouseCentor, this.getLocation(), "!");
		
		this.addMouseListener(new MouseAdapter() {
		});
		
		this.addMouseListener(new MouseAdapter() {

			/**
			 * 按下
			 */
			@Override
			public void mousePressed(MouseEvent e) {
				button = e.getButton();
				switch (button) {
				case 1:
					mouse.p1.setLocation(e.getPoint());
					mouse.p2.setLocation(e.getPoint());
					break;
				case 3:
					
					break;

				default:
					break;
				}
			}

			/**
			 * 抬起
			 */
			@Override
			public void mouseReleased(MouseEvent e) {
				int button = e.getButton();
				switch (button) {
				case 1:
					mouse.clear();
					break;
				case 3:
					oval.p3.setLocation(e.getPoint());
					oval.setInitial();
					break;

				default:
					break;
				}
			}
		});
		
		this.addMouseMotionListener(new MouseMotionListener() {
			
			@Override
			public void mouseMoved(MouseEvent e) {
//				System.out.println("移动");
			}
			
			@Override
			public void mouseDragged(MouseEvent e) {
				if(button == 1){
					mouse.p2.setLocation(e.getPoint());
				}

//				System.out.println("拖动");
			}
		});
		
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
	
	public void paint(Graphics g){
//		mouse.draw(g);
//		m.draw(g);
		mouse.draw(g);
		oval.draw(g);
	}
	
	
	public static void main(String[] args) {
		new GameFrame();
	}
	
}
